import {Iaction} from '../../utils/interface';

const initialState = {
    banner:[],
    brandList:[],
    categoryList:[],
    channel:[],
    hotGoodsList:[],
    newGoodsList:[],
    topicList:[],
    brand:{},
    goodsInfo:{},
    type:{}
}

const actions:any = {
    'INIT_HOME':(state:any,action:Iaction)=>{
        state=Object.assign(state,action.payload)
    },
    'INIT_BRAND':(state:any,action:Iaction)=>{
        state=Object.assign(state,action.payload)
    },
    'INIT_CART':(state:any,action:Iaction)=>{
        state=Object.assign(state,{goodsInfo:action.payload})
    },
    'INIT_RELATED':(state:any,action:Iaction)=>{
        state=Object.assign(state,action.payload)
    },
    'CART_INFO':(state:any,action:Iaction)=>{
        state=Object.assign(state,action.payload)
    },
    'ADD_COLLECT':(state:any,action:Iaction)=>{
        state=Object.assign(state,action.payload)
    },
    'ADD_CART':(state:any,action:Iaction)=>{
        // state=Object.assign(state,action.payload)
    },
    'ADD_COMMENT':(state:any,action:Iaction)=>{
        // state=Object.assign(state,action.payload)
    },
}

const reducer = function(state=initialState,action:Iaction){
    const newState = JSON.parse(JSON.stringify(state));
    actions[action.type] && actions[action.type](newState,action);
    return newState
}

export default reducer